package com.fihtdc.excelreader;

import java.util.ArrayList;

public class ModelDetail {
    private enum KEY_TYPE {
        platform, presign, media, releasekey
    };

    private final int         COMPONENT_TYPE       = 1; // B
    private final int         PROJECT              = 2; // C
    private final int         COMPONENT_NAME       = 3; // D
    private final int         COMPONENT_ID         = 5; // F
    private final int         VERSION              = 6; // G
    private final int         FILE_NAME            = 7; // H
    private final int         FILE_TYPE            = 8; // I
    private final int         SIGN_KEY             = 9; // J
    private final int         INTERGRATION_OPTIONS = 10; // K
    private final int         RESERVED_FILE        = 11; // L

    private Model             model;
    private ArrayList<String> ComponentType;
    private ArrayList<String> Project;
    private ArrayList<String> ComponentName;
    private ArrayList<String> ComponentId;
    private ArrayList<String> Version;
    private ArrayList<String> FileName;
    private ArrayList<String> FileType;
    private ArrayList<String> SignKey;
    private ArrayList<String> IntergratingOptions;
    private ArrayList<String> ReservedFile;

    public ModelDetail() {
        model = new Model();
        ComponentType = new ArrayList<String>();
        Project = new ArrayList<String>();
        ComponentName = new ArrayList<String>();
        ComponentId = new ArrayList<String>();
        Version = new ArrayList<String>();
        FileName = new ArrayList<String>();
        FileType = new ArrayList<String>();
        SignKey = new ArrayList<String>();
        IntergratingOptions = new ArrayList<String>();
        ReservedFile = new ArrayList<String>();
    }

    public Model getModel() {
        return model;
    }

    public void setModel(Model model) {
        this.model = model;
    }

    public ArrayList<String> getComponentType() {
        return ComponentType;
    }

    public void setComponentType(ArrayList<String> ComponentType) {
        checkSpace(ComponentType);
        this.ComponentType = ComponentType;
    }

    public ArrayList<String> getProject() {
        return Project;
    }

    public void setProject(ArrayList<String> Project) {
        checkSpace(Project);
        this.Project = Project;
    }

    public ArrayList<String> getComponentName() {
        return ComponentName;
    }

    public void setConponentName(ArrayList<String> ComponentName) {
        checkSpace(ComponentName);
        this.ComponentName = ComponentName;
    }

    public ArrayList<String> getComponentId() {
        return ComponentId;
    }

    public void setConponentId(ArrayList<String> ComponentId) {
        checkSpace(ComponentId);
        this.ComponentId = ComponentId;
    }

    public ArrayList<String> getVersion() {
        return Version;
    }

    public void setVersion(ArrayList<String> Version) {
        checkSpace(Version);
        this.Version = Version;
    }

    public ArrayList<String> getFileName() {
        return FileName;
    }

    public void setFileName(ArrayList<String> FileName) {
        checkSpace(FileName);
        this.FileName = FileName;
    }

    public ArrayList<String> getFileType() {
        return FileType;
    }

    public void setFileType(ArrayList<String> FileType) {
        checkSpace(FileType);
        this.FileType = FileType;
    }

    public ArrayList<String> getSignKey() {
        return SignKey;
    }

    public void setSignKey(ArrayList<String> SignKey) {
        checkSpace(SignKey);
        this.SignKey = SignKey;
    }

    public ArrayList<String> getIntergratingOptions() {
        return IntergratingOptions;
    }

    public void setIntergratingOptions(ArrayList<String> IntergratingOptions) {
        checkSpace(IntergratingOptions);
        this.IntergratingOptions = IntergratingOptions;
    }

    public ArrayList<String> getReservedFile() {
        return ReservedFile;
    }

    public void setReservedFile(ArrayList<String> ReservedFile) {
        checkSpace(ReservedFile);
        this.ReservedFile = ReservedFile;
    }

    public void setAttr(ArrayList<String> attr, int attr_index) {
        checkSpace(attr);
        switch (attr_index) {
            case COMPONENT_TYPE:
                ComponentType = attr;
                break;
            case PROJECT:
                Project = attr;
                break;
            case COMPONENT_NAME:
                ComponentName = attr;
                break;
            case COMPONENT_ID:
                ComponentId = attr;
                break;
            case VERSION:
                Version = attr;
                break;
            case FILE_NAME:
                FileName = attr;
                break;
            case FILE_TYPE:
                FileType = attr;
                break;
            case SIGN_KEY:
                for (String s : attr) {
                    if (s.equals("")) {
                        SignKey.add(s + ",");
                    } else if (s.equals(KEY_TYPE.presign.toString())) {
                        SignKey.add("presign,presign");
                    } else {
                        SignKey.add(s + ".x509.pem," + s + ".pk8");
                    }
                }
                break;
            case INTERGRATION_OPTIONS:
                IntergratingOptions = attr;
                break;
            case RESERVED_FILE:
                ReservedFile = attr;
                break;
        }
    }

    public ArrayList<String> getAttr(int attr_index) {
        switch (attr_index) {
            case COMPONENT_TYPE:
                return ComponentType;
            case PROJECT:
                return Project;
            case COMPONENT_NAME:
                return ComponentName;
            case COMPONENT_ID:
                return ComponentId;
            case VERSION:
                return Version;
            case FILE_NAME:
                return FileName;
            case FILE_TYPE:
                return FileType;
            case SIGN_KEY:
                return SignKey;
            case INTERGRATION_OPTIONS:
                return IntergratingOptions;
            case RESERVED_FILE:
                return ReservedFile;
        }
        return null;
    }

    private void checkSpace(ArrayList<String> arrayList) {
        for (int i = 0; i < arrayList.size(); i++) {
            String s = arrayList.get(i);
            if (arrayList.get(i).endsWith(" ")) {
                s = s.substring(0, s.lastIndexOf(" "));
                arrayList.set(i, s);
                checkSpace(arrayList);
            }
        }
    }
}
